package HomeWork;

public class Work_1 {
    public static void main(String[] args) {
        Person[] person=new Person[4];
        person[0]=new Student("李白",18,"男",2024101);
        person[1]=new Student("欣欣",17,"女",2024102);
        person[2]=new Teacher("星云",48,"男",20);
        person[3]=new Teacher("大帅",58,"男",30);
        Person person1 = new Person("666",23,"NAN");
        person1.sort(person);
        for (int i = 0; i < person.length; i++) {
            person[i].print();
        }






    }
}

//学生类
class Student extends Person {

    private int stu_id;

    //构造器
    public Student(String name, int age, String sex, int stu_id) {
        super(name, age, sex);
        this.stu_id = stu_id;
    }

    //方法
    public void study() {
        System.out.println("我承诺我会好好学习");
    }

    public String play() {
        return getName() + "爱玩足球";
    }

    public void print() {
        super.print();
        System.out.println("学号: " + stu_id);
        study();
        System.out.println(play());
        System.out.println("--------------------------");
    }

}
class Teacher extends Person{
    private int wage_age;//工龄

    public Teacher(String name, int age, String sex, int wage_age) {
        super(name, age, sex);
        this.wage_age = wage_age;
    }


    public void teach(){
        System.out.println("我承诺我会好好教书");
    }
    public String play(){
        return getName()+"爱玩下象棋";
    }
    public void print(){
        super.print();
        System.out.println("工龄: "+wage_age);
        teach();
        System.out.println(getName());
        System.out.println("--------------------------");
    }
}
class Person{
    private String name;
    private int age;
    private String sex;//性别

    public Person(String name, int age, String sex) {
        this.name = name;
        this.age = age;
        this.sex = sex;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }

    public String play(){
        return this.name+"爱玩";
    }
    public void print(){
        System.out.println("姓名: "+name+"\n"+"年龄: "+age+"\n"+"性别: "+sex);
    }

    //按年龄排序
    public void sort(Person[] p){
        for (int i = 0; i <p.length-1 ; i++) {
            for (int j = 0; j <p.length-1-i ; j++) {
                Person tem=null;
                if(p[j].age<p[j+1].age){
                    tem=p[j];
                    p[j]=p[j+1];
                    p[j+1]=tem;
                }
            }
        }
    }
}